package com.bosssoft.springboot.demo3.client;

import com.bosssoft.springboot.consumingwebservice.wsdl.GetMobileCodeInfo;
import com.bosssoft.springboot.consumingwebservice.wsdl.GetMobileCodeInfoResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;

/**
 * @author ChenTong
 * @version 1.0
 * @description 手机号归属地WebService客户端
 * @date 2020/6/13 8:03
 * @modified
 **/
@Slf4j
public class GetMobileInfoClient extends WebServiceGatewaySupport {
    private static final String ENDPOINT = "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx";
    private static final String SOAP_ACTION = "http://WebXml.com.cn/getMobileCodeInfo";

    public GetMobileCodeInfoResponse getMobileInfo(String phoneNum){
        GetMobileCodeInfo request = new GetMobileCodeInfo();
        request.setMobileCode(phoneNum);

        log.info("Requesting mobile info for :{}",phoneNum);

        return (GetMobileCodeInfoResponse) getWebServiceTemplate()
                .marshalSendAndReceive(ENDPOINT,request,
                        new SoapActionCallback(
                                SOAP_ACTION
                        ));
    }
}
